package com.lk.springboot.dao;

import com.lk.springboot.pojo.Task;
import com.lk.springboot.vo.TwoSpeed;
import com.lk.springboot.vo.UserTask;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author lk
 * @date 2020/1/11 0011 19:54
 */
@Mapper
public interface TaskMapper {

    //查询任务完成进度与总进度
    @Select("select speed,t_speed from u_t_solve,task  where  u_id=#{u_id} and u_t_solve.t_id=#{t_id} and u_t_solve.t_id=task.t_id ")
    TwoSpeed getSpeed(@Param("u_id") String u_id, @Param("t_id") String t_id);

    //任务奖励已领取，将任务的完成进度置为 999（作为标记）
    @Update("update  u_t_solve  set speed = 999 where  u_id=#{u_id} and t_id=#{t_id} ")
    void markAward(@Param("u_id") String u_id, @Param("t_id") String t_id);

    //获取任务详情
    @Select("select * from task where t_id=#{t_id}")
    Task getTask(String t_id);

    //增加积分
    @Update("update users set scores=scores + #{score} where u_id=#{u_id} ")
    void addScore(@Param("score") int score, @Param("u_id") String u_id);

    //根据sp_id获取该拼图的url
    @Select("select url from smallphoto where sp_id=#{sp_id}")
    String getSPUrl(String sp_id);

    // 获取当前积分
    @Select("select scores from users where u_id=#{u_id}")
    int getScore(String u_id);

    // 获取任务
    @Select("select * from task natural join u_t_solve where u_id=#{u_id}")
    List<UserTask> getUserTask(String u_id);


}
